<template>
  <view class="my-page">
    <!-- 标题栏 -->
    <nav-custom :showSearch="false"></nav-custom>
    <!-- 导航 -->
    <view class="order-nav">
      <scroll-view scroll-x="true" class="scroll-nav">
        <view class="nav-item padding-10" v-for="(item,index) in navList" :key="index" @click="handleNav(index)"
          :class="{'bgColor-ffe':navIdx === index}">
          <text class="color-2c">{{item}}</text>
        </view>
      </scroll-view>
    </view>
    <!-- 订单 -->
    <view class="orderItems">
      <order-item v-for="(item,index) in orderList" :key="index" :items="item"></order-item>
    </view>
  </view>
</template>

<script>
  import orderItem from "./order-item.vue"
  import {
    mapState
  } from 'vuex'
  export default {
    data() {
      return {
        state: {
          confirm: '0'
        },
        navList: ['全部', '待收货', '代付款', '待发货', '已完成'],
        page: 0,
        orderList: [],
        navStyle: 0,
        navIdx: 0,
      }
    },
    onLoad(opt) {
      console.log(opt);
      const {navIdx,confirm} = opt
      // ***页面传参传过来的为字符串
      this.navIdx = Number(navIdx)
      this.getOrderList()
    },
    // created() {
    //   this.state.confirm = this.$store.state.order.conf
    //   // this.$loadOrder()
    // },
    components: {
      "order-item": orderItem
    },
    computed: {
      ...mapState({
        userid: state => state.user.userInfo.objectId
      })
    },
    methods: {
      //   backDetail() {
      //     uni.navigateBack({
      //       delta: 1,
      //     })
      //   },
      getOrderList() {
        let userid = this.userid
        this.$H.get(`/1.1/classes/order?where={"userid":"${userid}"}`).then(res => {
          this.orderList = res.data.results
        })
      },
      handleNav(idx) {
        this.navIdx = idx
      },
      //   reloadData() {
      //     // 重启请求，清空数据
      //     this.orderList = []
      //     this.page = 0
      //     // this.$loadOrder()
      //   },
      //   ShareOn(state,id) {
      // 	this.navStyle = id
      //     // 接收上导航子组件
      //     if(state == 99){
      //       this.state.confirm = '99'
      //     }else{
      //       this.state.confirm = state
      //     }
      //     // console.log(result)
      //     this.reloadData()
      //   },
    },
    // onReachBottom() {
    //   // 上拉
    //   // this.$loadOrder()
    // },
    // onPullDownRefresh() {
    //   // 下拉
    //   // this.loadOrder()
    // },
    // onLoad(data){
    //   this.state.confirm = data.confirm
    //   this.navStyle = Number(data.navStyle)
    // }
  }
</script>

<style lang="scss" scoped>
  .orderItems {
    padding: 20rpx;
  }

  .scroll-nav {
    white-space: nowrap;
    background-color: #ededed;

    .nav-item {
      display: inline-block;
      width: 180rpx;
    }
  }
</style>
